#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int firstMissingPositive(vector<int>& nums)
    {
        int n = nums.size();
        for (int i = 0; i < n; i++)
        {
            while (nums[i] >= 1 && nums[i] <= n && nums[i] != nums[nums[i] - 1])
            {
                swap(nums[i], nums[nums[i] - 1]);
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (nums[i] != i + 1)
                return i + 1;
        }
        return n + 1;

    }
};

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums)
    {
        int len = nums.size();
        vector<int> f(len), g(len), ret(len);
        //f[i]表示[0，i-1]区间所有元素的乘积
        //g[i]表示[i+1,len-1]区间所有元素的乘积
        f[0] = 1;
        g[len - 1] = 1;
        for (int i = 1; i < len; i++)
        {
            f[i] = f[i - 1] * nums[i - 1];
        }
        for (int i = len - 2; i >= 0; i--)
        {
            g[i] = g[i + 1] * nums[i + 1];
        }
        for (int i = 0; i < len; i++)
        {
            ret[i] = f[i] * g[i];
        }
        return ret;


    }
};